﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.Models.DemographicQuestion>"
validateRequest="false" %>
<%@ Import Namespace="dbPoll_Application.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Demographic Question
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="pageHeadingContainer"><h2 class="pageHeading">
    Question Editor</h2></div>
    <div id="contentContainer">  
        <p>
           <%= Html.ActionLink("Polls > ", "Index", "Poll", null,
               new { @class = "breadcrumb" })%>
           <%= Html.ActionLink(ViewData["pollName"] + " > ", "Questions", 
               "Poll", new { pollID = ViewData["pollID"], 
                   pollName = ViewData["pollName"] }, 
                              new { @class = "breadcrumb" })%>
           Question <%= Model.questionNumber %>
        </p>
    <script src="../../Scripts/EditMCQ.js" type="text/javascript"></script>
    
    <% Html.EnableClientValidation();
       var pollRoles = ViewData["pollRoles"] as 
           ICollection<dbPoll_Application.Models.Role>;
       var pollCreator = new dbPoll_Application.Models.Role("Poll Creator");
       var pollAdministrator = 
           new dbPoll_Application.Models.Role("Poll Administrator");
       DateTime? pollClose = ViewData["pollClose"] as DateTime?;
       DateTime? pollStart = ViewData["pollStart"] as DateTime?;
    %>
        <% if (Model.questionID < 0)
       {
           Html.RenderPartial("PageMenu", Model);
       } %>
    <% String actionName;
       if (Model.questionID < 0)
       {
           actionName = "AddDemographic";
       }
       else {
           actionName = "UpdateDemographic";
       } %>
    <%  using (Ajax.BeginForm(actionName, 
            new AjaxOptions { OnSuccess = "onSubmitSuccess" }))
        { %>
       <input type="hidden" id="pollID" value="<%= ViewData["pollID"] %>"
        name="pollID" />
       <input type="hidden" id="pollName" value="<%= ViewData["pollName"] %>" 
       name="pollName" />  
       <% Html.RenderPartial("Question", Model); %>
       
       <div id="rightColumn">
       <div class="right">
       <ul class="rightColumnList" id="templateList">
           <li class="rightColumnListHeading"><h2>Participant Fields</h2></li>
           <% foreach (var field in ViewData["participantFields"] as 
                  List<dbPoll_Application.Models.ParticipantField>)
              {
                  if (Model.linkedField != null && field.fieldID == 
                      Model.linkedField.fieldID)
                  { %>
               <li class="rightColumnListItem participantFieldListItem 
               selectedParticipantField"><span class="none">
               <%= field.fieldID%></span><%= field.name%></li>
              <% }
                  else
                  { %>
               <li class="rightColumnListItem participantFieldListItem">
               <span class="none"><%= field.fieldID%></span><%= field.name%>
               </li> 
              <% }
              } %>
       </ul>
       <%= Html.HiddenFor(m => m.linkedField.fieldID) %>
       </div>
       <% Html.RenderPartial("QuestionObjects", Model); %>
       <% Html.RenderPartial("QuestionSettings", Model); %>
       <% Html.RenderPartial("ChartSettings", Model); %>
       </div>
       <div class="compareWith">
           <%= Html.HiddenFor(m => m.compareWith.questionID)%>
           <span class="left">Compare with:</span>
           <% var compareWith = ViewData["compareWith"] as String; %>
           <span class="searchCompareWith"><%= compareWith.CropAndTrail(40, "...") %></span>
           <span class="searchXCompareWith"><input type="button" value="Search" id="searchCompareQuestion" /></span>
           <span class="deleteCompareWith"><input type="button" value="Clear" id="clearCompareQuestion" /></span>
           <span>display chart 
           <%= Html.CheckBoxFor(m => m.comparisonChart.active)%></span>
           <%= Html.HiddenFor(m => m.comparisonChart.chartID)%>
           <%= Html.HiddenFor(m => m.comparisonChart.chartType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.valueType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.colours)%>
       </div>
       <% if (!(Model.questionID < 0))
          { %>
          <div id="convertToDemographicContainer">
              <span id="convertToDemographic">
                  <label>Convert to custom question:</label>
                  <input type="hidden" id="hasCompare" value="<%=ViewData["hasCompare"] as String%>" />
                  <button id="convertToCustomButton">Convert</button>
              </span>
          </div>
       <% 
          }
       
       %>
       <div class="clear"></div>
       <% } %>
       </div> 
       <script type="text/javascript" >
                  if (("<%= pollClose > DateTime.Now%>" == "True" && "<%=(!(pollRoles.Contains(pollCreator) || pollRoles.Contains(pollAdministrator)))%>" == "True")) {
                      document.getElementById("convertToCustomButton").disabled = true;
                  } else {
                      document.getElementById("convertToCustomButton").disabled = false;
                  }
       </script> 
       <% if (!(pollRoles.Contains(pollCreator) || 
              pollRoles.Contains(pollAdministrator)) || 
              (pollStart!=null && pollClose>DateTime.Now))
       {%><script type="text/javascript">
           $(document).ready(function() {
                  $('.participantFieldListItem').each(function() {
                      $(this).unbind();
                  });
              });
          </script>
          <style type="text/css">
            .participantFieldListItem:hover { background-color: White; }
            .selectedParticipantField:hover { background-color: #EAF0F4; }
          </style>
       <% } %>       
</asp:Content>